package com.kaaction.modules.test.api;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.kaaction.common.web.BaseController;
import com.kaaction.modules.test.entity.HqhscProduct;
import com.kaaction.modules.test.service.HqhscProductService;

@Controller
@RequestMapping(value = "api/v1/hqhsc/product")
public class HqhscProductApiController extends BaseController{

	@Autowired
	private HqhscProductService hqhscProductService;
	
	@RequestMapping(value = { "findListByArea" })
	public void findListByArea(HttpServletRequest request, HttpServletResponse response) throws IOException {
		HqhscProduct hqhscProduct = new HqhscProduct();
		String areaCode = request.getParameter("areaCode");
		String areaLevel = request.getParameter("areaLevel");
		List<HqhscProduct> list = new ArrayList<HqhscProduct>();
		if("1".equals(areaLevel))hqhscProduct.setAreaId(areaCode);
		else if("2".equals(areaLevel))hqhscProduct.setSubAreaId(areaCode);;
		
		list = hqhscProductService.findListByArea(hqhscProduct);
		super.writeAjaxResponse(response, list);
	}
	
	@RequestMapping(value = { "getProduct" })
	public void getProduct(HttpServletRequest request, HttpServletResponse response) throws IOException {
		String id = request.getParameter("id");
		HqhscProduct hqhscProduct = hqhscProductService.get(id);
		super.writeAjaxResponse(response, hqhscProduct);
	}
	
}
